﻿using System;
using System.Data;
using System.Web.UI.WebControls;
namespace BONSAI.Admin.UC
{
    public partial class DichVuManager : System.Web.UI.UserControl
    {
        /*protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindFact();
                BindStart();
            }
        }
        void BindFact()
        {
            ListItem list = new ListItem("Tất cả", "0");
            dropLoaiFact.DataSource = type.LoaiDichVu_Get(0);
            dropLoaiFact.DataTextField = "LoaiDichVu";
            dropLoaiFact.DataValueField = "ID";
            dropLoaiFact.DataBind();
            dropLoaiFact.Items.Insert(0, list);

            // bind drop type Fact F
            droploaiFactF.DataSource = type.LoaiDichVu_Get(0);
            droploaiFactF.DataTextField = "LoaiDichVu";
            droploaiFactF.DataValueField = "ID";
            droploaiFactF.DataBind();
            droploaiFactF.Items.Insert(0, list);

            // set value default

            if (Request.QueryString["type"] != null)
            {
                dropLoaiFact.SelectedValue = Request.QueryString["type"].ToString();
                dropLoaiFact.SelectedValue = Request.QueryString["type"].ToString();
            }
        }
        public void BindStart()
        {
            //// delete all
            //if (Request.QueryString["zxc"] != null)
            //{
            //    if (Request.QueryString["zxc"].ToString() == "1qwertyuiop")
            //    {
            //        em.Trainee_Delete(0);
            //    }
            //}
            ////=============

            DataTable table = dv.DichVu_Get(0,Int32.Parse(droploaiFactF.SelectedValue.ToString()));
            GridView1.DataSource = table;
            GridView1.DataBind();
         
        }
        
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindStart();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string key = GridView1.DataKeys[e.RowIndex].Value.ToString();
            dv.DichVu_Delete(Int32.Parse(key));
            BindStart();    
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           // GridView1.EditIndex = e.NewEditIndex;

            string key = GridView1.DataKeys[e.NewEditIndex].Value.ToString();

            DataTable table = dv.DichVu_Get(Int32.Parse(key),0);

            if (table.Rows.Count > 0)
            {
                txtma.Text = table.Rows[0]["ID"].ToString();
                txtfactTV.Text = table.Rows[0]["DichVu"].ToString();
                txtfactEN.Text = table.Rows[0]["DichVuEN"].ToString();
                dropLoaiFact.SelectedValue = table.Rows[0]["LoaiDihVuID"].ToString();
            }


            BindStart();
        }   
       

        protected void droploaiFactF_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindStart();
        }

        protected void bthemmoi_Click(object sender, EventArgs e)
        {
            if (txtfactTV.Text == "")
            {
                WebMBox.Show("Vui lòng nhập dịch vụ Tíếng Việt");
                return;
            }
            if (dropLoaiFact.SelectedValue.ToString() == "0")
            {
                WebMBox.Show("Vui lòng chọn loại dịch vụ.");
                return;
            }
            dv.DichVu_Insert(txtfactTV.Text, txtfactEN.Text, Int32.Parse(dropLoaiFact.SelectedValue.ToString()));
            BindStart();
            txtma.Text = "";
            WebMBox.Show("Thêm mới thành công");

        }

        protected void btcapnhat_Click1(object sender, EventArgs e)
        {
            if (txtma.Text == "")
            {
                WebMBox.Show("Vui lòng chọn chỉnh sửa ở danh sách bên dưới.");
                return;
            }
            if (txtfactTV.Text == "")
            {
                WebMBox.Show("Vui lòng nhập dịch vụ Tíếng Việt");
                return;
            }
            if (dropLoaiFact.SelectedValue.ToString() == "0")
            {
                WebMBox.Show("Vui lòng chọn loại dịch vụ.");
                return;
            }
            dv.DichVu_Update(txtfactTV.Text, txtfactEN.Text, Int32.Parse(dropLoaiFact.SelectedValue.ToString()),Int32.Parse(txtma.Text));
            BindStart();
            WebMBox.Show("Cập nhật thành công");
        }*/
    }
}